package com.jtjrenren.android.taxi.driver.core.setting;

import android.view.View;
import android.widget.TextView;

import com.jtjrenren.android.taxi.driver.bean.api.ApiDutyInfo;
import com.jtjrenren.android.taxi.driver.R;
import com.jtjrenren.android.taxi.driver.bean.DriverInfo;
import com.jtjrenren.android.taxi.driver.bean.api.CommonResult;
import com.jtjrenren.android.taxi.driver.manger.AppManger;

import com.jtjrenren.android.taxi.driver.base.BaseActivity;
import com.jtjrenren.android.taxi.driver.manger.api.ApiWorks;
import com.library.weiget.ClearEditText;
import com.library.utils.RegexUtils;
import com.library.utils.StringUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/5/5.
 */
public class SettingLcjdActivity extends BaseActivity {
    @BindView(R.id.lcjd_phone)
     ClearEditText et_phone;

    public ApiDutyInfo info;
    private DriverInfo driver;

    @Override
    public int getLayoutID() {
        return R.layout.aty_setting_lcjd;
    }

    @Override
    public void init() {
        if (getIntent().hasExtra("info")) {
            info = (ApiDutyInfo) getIntent().getExtras().get("info");
        }

        driver = AppManger.getInstance().driver;

        ((TextView) findViewById(R.id.title_title)).setText("离车接单");
        findViewById(R.id.title_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        refreshView(info);
    }

    @OnClick(R.id.lcjd_save)
    public void clickSave(){
        if (driver == null)
            return;

        String phone = et_phone.getText().toString().trim();
        if (StringUtils.isEmpty(phone) || !RegexUtils.isPhoneNo(phone)) {
            displayShort(getString(R.string.qingshuruzhengquedeshoujihao));
            return;
        }

        showProDialog(null, getString(R.string.shezhitishi));

        ApiWorks.setDriverRarelyDuty(driver.getWorkNo(), "0", phone, "", "", "", "", new ApiWorks.ResponseListener<CommonResult>() {
            @Override
            public void onResponse(CommonResult commonResult) {
                disProDialog();
                if (commonResult!=null&&commonResult.getCode()==1){
                    displayShort(getString(R.string.shezhichenggong));
                    finish();
                }else {
                    displayShort(getString(R.string.shezhishibai));
                }
            }
        });
    }
    private void refreshView(ApiDutyInfo info) {
        if (info == null)
            return;
        et_phone.setText(info.getMobilePhone() + "");
    }
}
